<template>
  <div class="list-container">
    <div class="list-item" v-for="(item, index) in imageList" :key="index">
      <img @click="openImg(item)" :src="item.picture" alt="" />
      <div class="xia">
        <div class="left">
          <p class="name">{{ item.name }}</p>
          <p class="an">
            <el-tag>{{ item.kindName ? item.kindName : "水体颜色" }}</el-tag>
            <span class="time">{{
              item.timestamp ? item.timestamp : "2024-05-10 09:09:09"
            }}</span>
          </p>
        </div>
        <div class="right">
          <el-button
            type="primary"
            icon="el-icon-refresh-left"
            @click="openVideo(item)"
            >查看回放</el-button
          >
        </div>
      </div>
    </div>
    <!-- 图片 -->
    <My-Dialog
      v-if="dialogVisibleCopyImage"
      :dialogVisibleFa.sync="dialogVisibleCopyImage"
      widthValue="1000px"
      dialogTitle="告警信息查看"
      :isCenter="true"
    >
      <OpenView
        v-if="dialogVisibleCopyImage"
        :dialogVisibleUse.sync="dialogVisibleCopyImage"
        :openImgData="openImgData"
      />
    </My-Dialog>
    <!-- 视频 -->
    <el-dialog
      v-if="dialogVisibleCopyVideo"
      :close-on-click-modal="false"
      :visible.sync="dialogVisibleCopyVideo"
      width="950px"
      title="视频"
    >
      <BackView
        v-if="dialogVisibleCopyVideo"
        :dialogVisibleUse.sync="dialogVisibleCopyVideo"
        :openVideoData="openVideoData"
      />
    </el-dialog>
  </div>
</template>

<script>
import MyDialog from "@/components/MyDialog/index.vue";
import OpenView from "./OpenView.vue";
import BackView from "./back/BackView.vue";
import { getToken } from "@/utils/auth";
import axios from "axios";
export default {
  name: "ListView",
  components: { MyDialog, BackView, OpenView },
  props: ["tableData", "freezeData"],
  data() {
    return {
      loading: true,
      dataBlobs: [],
      //图片
      dialogVisibleCopyImage: false,
      openImgData: {},
      //视频
      dialogVisibleCopyVideo: false,
      openVideoData: {},
    };
  },
  // watch: {
  //   tableData: {
  //     handler(newVal, oldVal) {
  //       this.tableData.forEach((item, index) => {
  //         this.getViewImg(item, index);
  //       });
  //     },
  //   },
  // },
  computed: {
    imageList() {
      return this.tableData;
    },
  },
  // mounted() {
  //   this.$nextTick(() => {
  //     this.tableData.forEach((item, index) => {
  //       this.getViewImg(item, index);
  //     });
  //   });
  // },
  methods: {
    openImg(e) {
      this.freezeData.filter((item) => {
        if (item.event_id === e.event_id) {
          this.openImgData = item;
        }
      });
      this.dialogVisibleCopyImage = true;
    },
    // 打开回放弹框
    openVideo(e) {
      this.dialogVisibleCopyVideo = true;
      this.openVideoData = e;
    },
    // 请求图片
    async getViewImg(item, index) {
      const response = await axios.get(
        "http://10.194.185.226:5001/ytpt/alarm/getViewImg?imgPath=" +
          item.picture,
        {
          responseType: "blob",
          headers: {
            Authorization: "Bearer " + getToken(),
          },
        }
      );
      const blob = response.data;
      this.imageList[index].picture = URL.createObjectURL(blob);
    },
  },
  beforeDestroy() {},
};
</script>

<style scoped lang="scss">
::-webkit-scrollbar {
  visibility: hidden;
  width: 2px; /* 垂直滚动条的宽度 */
  height: 10px; /* 水平滚动条的高度 */
}
.list-container {
  padding-left: 5px;
  height: 690px;
  display: flex;
  align-items: start;
  flex-wrap: wrap;
  overflow-y: scroll;
  // min-width: 1460px;
  .list-item {
    margin-right: 1%;
    margin-top: 15px;
    width: 24%;
    min-width: 360px;
    height: 330px;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    img {
      width: 100%;
      height: 253px;
    }
    .xia {
      padding: 8px 12px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-family: "Source Han Sans CN";
      .name {
        font-weight: 500;
        font-size: 16px;
        color: #606163;
      }
      .an {
        margin-top: 3px;
        display: flex;
        align-items: center;
        .time {
          display: inline-block;
          background: rgba(204, 204, 204, 0.1);
          border-radius: 4px;
          border: 1px solid #e5e5e5;
          opacity: 0.5;
          font-weight: 400;
          font-size: 14px;
          color: #999999;
          height: 24px;
          line-height: 24px;
          margin-left: 5px;
        }
      }
      p {
        margin: 0;
        padding: 0;
        min-width: 240px;
      }
    }
  }
}
</style>
